package com.synchronization;


class MyThread implements java.lang.Runnable {
	private int threadId;

	public MyThread(int id) {
		this.threadId = id;
	}

	public void run() {
		Integer num = 1;
		System.out.println(threadId);
		try {
			Thread.sleep(1000 * 60);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
//		if(threadId % 2 == 0){testSynchronized1(); }else{testSynchronized2();};
		
//		Integer num2 = new Integer(1);
//		System.out.println(num == num2);
		final String str = "mytask" + num;
//		synchronized (str) {
//			for (int i = 0; i < 100; ++i) {
//				System.out.println("Thread ID: " + this.threadId + " : " + i);
//			}
//		}
		
	}
	
	public synchronized void testSynchronized1(){
		System.out.println(threadId + "----------" + 1);
		for (int i = 0; i < 100; ++i) {
			System.out.println("Thread ID: " + this.threadId + " : " + i);
		}
	}
	
	public synchronized void testSynchronized2(){
		System.out.println(threadId + "----------" + 2);
		for (int i = 0; i < 100; ++i) {
			System.out.println("Thread ID: " + this.threadId + " : " + i);
		}
	}
	
	public void setThreadId(int threadId){
		this.threadId = threadId;
	}
}

public class ThreadDemo {
	/**
	* @param args
	* @throws InterruptedException
	*/
	public static void main(String[] args) throws InterruptedException {
		MyThread myThread = new MyThread(0);
		for (int i = 0; i < 10; ++i) {
//			myThread.setThreadId(i);
			new Thread(new MyThread(i)).start();
//			Thread.sleep(1);
		}
	}
}